<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Java-基础（面试） | Hexo</title>
  <meta name="keywords" content=" Java基础 ">
  <meta name="description" content="Java-基础（面试） | Hexo">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="description" content="如何解决消息过期失效问题RabbtiMQ 是可以设置过期时间的，也就是 TTL。如果消息在 queue 中积压超过一定的时间就会被 RabbitMQ 给清理掉，这个数据就没了。这就是说数据不会大量积压在 mq 里，而是大量的数据会直接搞丢。解决方法就是采用批量重导。 批量重导，也就是后期的一种手动补偿手段。当高峰期过去之后将丢失的那部分数据，写个临时程序查出来，重新放到MQ里，把白天的数据补回来。">
<meta property="og:type" content="article">
<meta property="og:title" content="Rabbit MQ（面试）">
<meta property="og:url" content="https://xiaomaer-sss.gitee.io/xiaomaer-sss/2023/02/03/Rabbit%20MQ%EF%BC%88%E9%9D%A2%E8%AF%95%EF%BC%89/index.html">
<meta property="og:site_name" content="Hexo">
<meta property="og:description" content="如何解决消息过期失效问题RabbtiMQ 是可以设置过期时间的，也就是 TTL。如果消息在 queue 中积压超过一定的时间就会被 RabbitMQ 给清理掉，这个数据就没了。这就是说数据不会大量积压在 mq 里，而是大量的数据会直接搞丢。解决方法就是采用批量重导。 批量重导，也就是后期的一种手动补偿手段。当高峰期过去之后将丢失的那部分数据，写个临时程序查出来，重新放到MQ里，把白天的数据补回来。">
<meta property="og:locale" content="en_US">
<meta property="article:published_time" content="2023-02-03T13:04:21.063Z">
<meta property="article:modified_time" content="2023-02-04T03:42:41.460Z">
<meta property="article:author" content="kiwi">
<meta property="article:tag" content="队列">
<meta property="article:tag" content="异步">
<meta name="twitter:card" content="summary">


<link rel="icon" href="/img/avatar.jpg">

<link href="/css/style.css?v=1.1.0" rel="stylesheet">

<link href="/css/hl_theme/atom-light.css?v=1.1.0" rel="stylesheet">

<link href="//cdn.jsdelivr.net/npm/animate.css@4.1.0/animate.min.css" rel="stylesheet">

<script src="//cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.min.js"></script>
<script src="/js/titleTip.js?v=1.1.0" ></script>

<script src="//cdn.jsdelivr.net/npm/highlightjs@9.16.2/highlight.pack.min.js"></script>
<script>
    hljs.initHighlightingOnLoad();
</script>

<script src="//cdn.jsdelivr.net/npm/nprogress@0.2.0/nprogress.min.js"></script>



<script src="//cdn.jsdelivr.net/npm/jquery.cookie@1.4.1/jquery.cookie.min.js" ></script>

<script src="/js/iconfont.js?v=1.1.0" ></script>

<meta name="generator" content="Hexo 5.4.2"></head>
<div style="display: none">
  <input class="theme_disqus_on" value="false">
  <input class="theme_preload_comment" value="">
  <input class="theme_blog_path" value="">
  <input id="theme_shortcut" value="true" />
  <input id="theme_highlight_on" value="true" />
  <input id="theme_code_copy" value="true" />
</div>



<body>
<aside class="nav">
    <div class="nav-left">
        <a href="/"
   class="avatar_target">
    <img class="avatar"
         src="/img/avatar.jpg"/>
</a>
<div class="author">
    <span>kiwi</span>
</div>

<div class="icon">
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
            <a title="csdn"
               href="https://blog.csdn.net/weixin_45340300?type=blog"
               target="_blank">
                
                    <svg class="iconfont-svg" aria-hidden="true">
                        <use xlink:href="#icon-csdn"></use>
                    </svg>
                
            </a>
        
    
        
    
        
    
        
            <a title="email"
               href="mailto:jackma.h@foxmail.com"
               target="_blank">
                
                    <svg class="iconfont-svg" aria-hidden="true">
                        <use xlink:href="#icon-email"></use>
                    </svg>
                
            </a>
        
    
        
            <a title="qq"
               href="http://wpa.qq.com/msgrd?v=3&uin=761791958&site=qq&menu=yes"
               target="_blank">
                
                    <svg class="iconfont-svg" aria-hidden="true">
                        <use xlink:href="#icon-qq"></use>
                    </svg>
                
            </a>
        
    
        
    
        
    
</div>




<ul>
    <li>
        <div class="all active" data-rel="All">All
            
                <small>(34)</small>
            
        </div>
    </li>
    
        
            
                <li>
                    <div data-rel="开发">
                        <i class="fold iconfont icon-right"></i>
                        
                        开发
                        <small>(34)</small>
                        
                    </div>
                    
                        <ul class="sub hide">
                            
                                <li>
                                    <div data-rel="开发<--->框架">
                                        
                                        框架
                                        
                                            <small>(14
                                                )</small>
                                        
                                    </div>
                                    
                                </li>
                            
                                <li>
                                    <div data-rel="开发<--->其他">
                                        
                                        其他
                                        
                                            <small>(5
                                                )</small>
                                        
                                    </div>
                                    
                                </li>
                            
                                <li>
                                    <div data-rel="开发<--->数据库">
                                        
                                        数据库
                                        
                                            <small>(2
                                                )</small>
                                        
                                    </div>
                                    
                                </li>
                            
                                <li>
                                    <div data-rel="开发<--->疑难杂症">
                                        
                                        疑难杂症
                                        
                                            <small>(2
                                                )</small>
                                        
                                    </div>
                                    
                                </li>
                            
                                <li>
                                    <div data-rel="开发<--->中间件">
                                        
                                        中间件
                                        
                                            <small>(5
                                                )</small>
                                        
                                    </div>
                                    
                                </li>
                            
                                <li>
                                    <div data-rel="开发<--->Java">
                                        
                                        Java
                                        
                                            <small>(6
                                                )</small>
                                        
                                    </div>
                                    
                                </li>
                            
                        </ul>
                    
                </li>
            
        
    
        
            
        
    
        
            
        
    
        
            
        
    
        
            
        
    
        
            
        
    
        
            
        
    
</ul>
<div class="left-bottom">
    <div class="menus">
        
            
            
            
    </div>
    <div>
        
        
    </div>
</div>
<input type="hidden" id="yelog_site_posts_number" value="34">
<input type="hidden" id="yelog_site_word_count" value="83.6k">
<div style="display: none">
    <span id="busuanzi_value_site_uv"></span>
    <span id="busuanzi_value_site_pv"></span>
</div>

    </div>
    <div class="nav-right">
        <div class="friends-area">
    <div class="friends-title">
        Links
        <i class="iconfont icon-left"></i>
    </div>
    <div class="friends-content">
        <ul>
            
            <li><a target="_blank" href="https://xiaomaer-sss.gitee.io/">叶落阁</a></li>
            
        </ul>
    </div>
</div>
        <div class="title-list">
    <div class="right-top">
        <div id="default-panel">
            <i class="iconfont icon-search" data-title="搜索 快捷键 i"></i>
            <div class="right-title">All</div>
            <i class="iconfont icon-file-tree" data-title="切换到大纲视图 快捷键 w"></i>
        </div>
        <div id="search-panel">
            <i class="iconfont icon-left" data-title="返回"></i>
            <input id="local-search-input" autocomplete="off"/>
            <label class="border-line" for="input"></label>
            <i class="iconfont icon-case-sensitive" data-title="大小写敏感"></i>
            <i class="iconfont icon-tag" data-title="标签"></i>
        </div>
        <div id="outline-panel" style="display: none">
            <div class="right-title">大纲</div>
            <i class="iconfont icon-list" data-title="切换到文章列表"></i>
        </div>
    </div>

    <div class="tags-list">
    <input id="tag-search" />
    <div class="tag-wrapper">
        
            <li class="article-tag-list-item">
                <i class="iconfont icon-tag"></i><a>队列</a>
            </li>
        
            <li class="article-tag-list-item">
                <i class="iconfont icon-tag"></i><a>分布式</a>
            </li>
        
            <li class="article-tag-list-item">
                <i class="iconfont icon-tag"></i><a>缓存</a>
            </li>
        
            <li class="article-tag-list-item">
                <i class="iconfont icon-tag"></i><a>流式处理</a>
            </li>
        
            <li class="article-tag-list-item">
                <i class="iconfont icon-tag"></i><a>区块链</a>
            </li>
        
            <li class="article-tag-list-item">
                <i class="iconfont icon-tag"></i><a>实战面试题</a>
            </li>
        
            <li class="article-tag-list-item">
                <i class="iconfont icon-tag"></i><a>数据库</a>
            </li>
        
            <li class="article-tag-list-item">
                <i class="iconfont icon-tag"></i><a>异步</a>
            </li>
        
            <li class="article-tag-list-item">
                <i class="iconfont icon-tag"></i><a>Bug</a>
            </li>
        
            <li class="article-tag-list-item">
                <i class="iconfont icon-tag"></i><a>Docker</a>
            </li>
        
            <li class="article-tag-list-item">
                <i class="iconfont icon-tag"></i><a>Java</a>
            </li>
        
            <li class="article-tag-list-item">
                <i class="iconfont icon-tag"></i><a>Java-集合</a>
            </li>
        
            <li class="article-tag-list-item">
                <i class="iconfont icon-tag"></i><a>Java-进阶</a>
            </li>
        
            <li class="article-tag-list-item">
                <i class="iconfont icon-tag"></i><a>Java-JVM</a>
            </li>
        
            <li class="article-tag-list-item">
                <i class="iconfont icon-tag"></i><a>Java基础</a>
            </li>
        
            <li class="article-tag-list-item">
                <i class="iconfont icon-tag"></i><a>LB</a>
            </li>
        
            <li class="article-tag-list-item">
                <i class="iconfont icon-tag"></i><a>MQ</a>
            </li>
        
            <li class="article-tag-list-item">
                <i class="iconfont icon-tag"></i><a>Mybatis</a>
            </li>
        
            <li class="article-tag-list-item">
                <i class="iconfont icon-tag"></i><a>MySQL</a>
            </li>
        
            <li class="article-tag-list-item">
                <i class="iconfont icon-tag"></i><a>Redis</a>
            </li>
        
            <li class="article-tag-list-item">
                <i class="iconfont icon-tag"></i><a>Spring</a>
            </li>
        
            <li class="article-tag-list-item">
                <i class="iconfont icon-tag"></i><a>Spring Cloud Alibaba</a>
            </li>
        
            <li class="article-tag-list-item">
                <i class="iconfont icon-tag"></i><a>SpringBoot</a>
            </li>
        
    </div>

</div>

    
    <nav id="title-list-nav">
        
        
        <a  class="All 开发 中间件 "
           href="/xiaomaer-sss/2023/02/03/Rabbit%20MQ%EF%BC%88%E9%9D%A2%E8%AF%95%EF%BC%89/"
           data-tag="队列,异步"
           data-author="" >
            <span class="post-title" title="Rabbit MQ（面试）">Rabbit MQ（面试）</span>
            <span class="post-date" title="2023-02-03 21:04:21">2023/02/03</span>
        </a>
        
        
        <a  class="All 开发 Java "
           href="/xiaomaer-sss/2023/02/03/%E5%AE%9E%E6%88%98%E9%9D%A2%E8%AF%95%E9%A2%98%EF%BC%88%E9%9D%A2%E8%AF%95%EF%BC%89/"
           data-tag="实战面试题"
           data-author="" >
            <span class="post-title" title="实战面试题">实战面试题</span>
            <span class="post-date" title="2023-02-03 17:11:07">2023/02/03</span>
        </a>
        
        
        <a  class="All 开发 中间件 "
           href="/xiaomaer-sss/2023/02/02/Kafka%EF%BC%88%E9%9D%A2%E8%AF%95%EF%BC%89/"
           data-tag="分布式,流式处理,MQ"
           data-author="" >
            <span class="post-title" title="Kafka（面试）">Kafka（面试）</span>
            <span class="post-date" title="2023-02-02 09:51:06">2023/02/02</span>
        </a>
        
        
        <a  class="All 开发 中间件 "
           href="/xiaomaer-sss/2023/02/02/Zookeeper%EF%BC%88%E9%9D%A2%E8%AF%95%EF%BC%89/"
           data-tag="分布式"
           data-author="" >
            <span class="post-title" title="Zookeeper（面试）">Zookeeper（面试）</span>
            <span class="post-date" title="2023-02-02 09:50:33">2023/02/02</span>
        </a>
        
        
        <a  class="All 开发 中间件 "
           href="/xiaomaer-sss/2023/02/01/Redis%EF%BC%88%E9%9D%A2%E8%AF%95%EF%BC%89/"
           data-tag="Redis,缓存"
           data-author="" >
            <span class="post-title" title="Redis（面试）">Redis（面试）</span>
            <span class="post-date" title="2023-02-01 14:09:09">2023/02/01</span>
        </a>
        
        
        <a  class="All 开发 框架 "
           href="/xiaomaer-sss/2023/01/30/SpringBoot%EF%BC%88%E9%9D%A2%E8%AF%95%EF%BC%89/"
           data-tag="SpringBoot"
           data-author="" >
            <span class="post-title" title="SpringBoot（面试）">SpringBoot（面试）</span>
            <span class="post-date" title="2023-01-30 20:26:42">2023/01/30</span>
        </a>
        
        
        <a  class="All 开发 框架 "
           href="/xiaomaer-sss/2023/01/30/Mybatis%EF%BC%88%E9%9D%A2%E8%AF%95%EF%BC%89/"
           data-tag="Mybatis"
           data-author="" >
            <span class="post-title" title="Mybatis（面试）">Mybatis（面试）</span>
            <span class="post-date" title="2023-01-30 19:13:44">2023/01/30</span>
        </a>
        
        
        <a  class="All 开发 框架 "
           href="/xiaomaer-sss/2023/01/30/Spring%EF%BC%88%E9%9D%A2%E8%AF%95%EF%BC%89/"
           data-tag="Spring"
           data-author="" >
            <span class="post-title" title="Spring（面试）">Spring（面试）</span>
            <span class="post-date" title="2023-01-30 19:12:30">2023/01/30</span>
        </a>
        
        
        <a  class="All 开发 Java "
           href="/xiaomaer-sss/2023/01/29/Java-JVM%EF%BC%88%E9%9D%A2%E8%AF%95%EF%BC%89/"
           data-tag="Java-JVM"
           data-author="" >
            <span class="post-title" title="Java-JVM（面试）">Java-JVM（面试）</span>
            <span class="post-date" title="2023-01-29 16:31:34">2023/01/29</span>
        </a>
        
        
        <a  class="All 开发 Java "
           href="/xiaomaer-sss/2023/01/29/Java-%E8%BF%9B%E9%98%B6%EF%BC%88%E9%9D%A2%E8%AF%95%EF%BC%89/"
           data-tag="Java-进阶"
           data-author="" >
            <span class="post-title" title="Java-进阶（面试）">Java-进阶（面试）</span>
            <span class="post-date" title="2023-01-29 13:11:10">2023/01/29</span>
        </a>
        
        
        <a  class="All 开发 Java "
           href="/xiaomaer-sss/2023/01/29/Java-%E9%9B%86%E5%90%88%EF%BC%88%E9%9D%A2%E8%AF%95%EF%BC%89/"
           data-tag="Java-集合"
           data-author="" >
            <span class="post-title" title="Java-集合（面试）">Java-集合（面试）</span>
            <span class="post-date" title="2023-01-29 09:18:51">2023/01/29</span>
        </a>
        
        
        <a  class="All 开发 数据库 "
           href="/xiaomaer-sss/2023/01/28/%E6%95%B0%E6%8D%AE%E5%BA%93-MySQL%EF%BC%88%E9%9D%A2%E8%AF%95%EF%BC%89/"
           data-tag="MySQL"
           data-author="" >
            <span class="post-title" title="数据库-MySQL（面试）">数据库-MySQL（面试）</span>
            <span class="post-date" title="2023-01-28 16:50:59">2023/01/28</span>
        </a>
        
        
        <a  class="All 开发 Java "
           href="/xiaomaer-sss/2023/01/27/Java-%E5%9F%BA%E7%A1%80%EF%BC%88%E9%9D%A2%E8%AF%95%EF%BC%89/"
           data-tag="Java基础"
           data-author="" >
            <span class="post-title" title="Java-基础（面试）">Java-基础（面试）</span>
            <span class="post-date" title="2023-01-27 19:42:58">2023/01/27</span>
        </a>
        
        
        <a  class="All 开发 其他 "
           href="/xiaomaer-sss/2023/01/27/%E5%8C%BA%E5%9D%97%E9%93%BE%E9%92%B1%E5%8C%85/"
           data-tag="区块链"
           data-author="" >
            <span class="post-title" title="区块链钱包">区块链钱包</span>
            <span class="post-date" title="2023-01-27 18:57:51">2023/01/27</span>
        </a>
        
        
        <a  class="All 开发 其他 "
           href="/xiaomaer-sss/2023/01/27/Truffle%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4/"
           data-tag="区块链"
           data-author="" >
            <span class="post-title" title="Truffle常用命令&amp;Web3常用方法">Truffle常用命令&amp;Web3常用方法</span>
            <span class="post-date" title="2023-01-27 18:57:51">2023/01/27</span>
        </a>
        
        
        <a  class="All 开发 其他 "
           href="/xiaomaer-sss/2023/01/27/Truffle&OpenZeppelin%E7%8E%AF%E5%A2%83%E6%90%AD%E5%BB%BA/"
           data-tag="区块链"
           data-author="" >
            <span class="post-title" title="Truffle&amp;OpenZeppelin环境搭建">Truffle&amp;OpenZeppelin环境搭建</span>
            <span class="post-date" title="2023-01-27 18:57:51">2023/01/27</span>
        </a>
        
        
        <a  class="All 开发 其他 "
           href="/xiaomaer-sss/2023/01/27/Solidity/"
           data-tag="区块链"
           data-author="" >
            <span class="post-title" title="Solidity">Solidity</span>
            <span class="post-date" title="2023-01-27 18:57:51">2023/01/27</span>
        </a>
        
        
        <a  class="All 开发 中间件 "
           href="/xiaomaer-sss/2023/01/27/Nginx/"
           data-tag="LB"
           data-author="" >
            <span class="post-title" title="Nginx">Nginx</span>
            <span class="post-date" title="2023-01-27 18:57:51">2023/01/27</span>
        </a>
        
        
        <a  class="All 开发 框架 "
           href="/xiaomaer-sss/2023/01/27/DockerFile/"
           data-tag="Docker"
           data-author="" >
            <span class="post-title" title="Dockerfile">Dockerfile</span>
            <span class="post-date" title="2023-01-27 17:45:23">2023/01/27</span>
        </a>
        
        
        <a  class="All 开发 其他 "
           href="/xiaomaer-sss/2023/01/27/%E5%8C%BA%E5%9D%97%E9%93%BE%E4%B9%8B%E4%BB%A5%E5%A4%AA%E5%9D%8A/"
           data-tag="区块链"
           data-author="" >
            <span class="post-title" title="区块链之以太坊">区块链之以太坊</span>
            <span class="post-date" title="2023-01-27 17:45:23">2023/01/27</span>
        </a>
        
        
        <a  class="All 开发 数据库 "
           href="/xiaomaer-sss/2023/01/27/%E5%B8%B8%E7%94%A8SQL%E8%AF%AD%E6%B3%95%E6%95%B4%E7%90%86/"
           data-tag="MySQL,数据库"
           data-author="" >
            <span class="post-title" title="常用SQL语法整理">常用SQL语法整理</span>
            <span class="post-date" title="2023-01-27 17:45:23">2023/01/27</span>
        </a>
        
        
        <a  class="All 开发 框架 "
           href="/xiaomaer-sss/2023/01/27/docker%E8%BF%9B%E9%98%B6/"
           data-tag="Docker"
           data-author="" >
            <span class="post-title" title="Docker进阶">Docker进阶</span>
            <span class="post-date" title="2023-01-27 17:45:23">2023/01/27</span>
        </a>
        
        
        <a  class="All 开发 框架 "
           href="/xiaomaer-sss/2023/01/27/Docker%E5%9F%BA%E7%A1%80/"
           data-tag="Docker"
           data-author="" >
            <span class="post-title" title="Docker基础">Docker基础</span>
            <span class="post-date" title="2023-01-27 17:45:23">2023/01/27</span>
        </a>
        
        
        <a  class="All 开发 框架 "
           href="/xiaomaer-sss/2023/01/27/Docker%E5%AE%89%E8%A3%85%E5%B8%B8%E8%A7%81%E7%BB%84%E4%BB%B6/"
           data-tag="Docker"
           data-author="" >
            <span class="post-title" title="Docker安装常见组件">Docker安装常见组件</span>
            <span class="post-date" title="2023-01-27 17:45:23">2023/01/27</span>
        </a>
        
        
        <a  class="All 开发 框架 "
           href="/xiaomaer-sss/2023/01/26/SkyWalking/"
           data-tag="Spring Cloud Alibaba"
           data-author="" >
            <span class="post-title" title="SkyWalking">SkyWalking</span>
            <span class="post-date" title="2023-01-26 21:39:44">2023/01/26</span>
        </a>
        
        
        <a  class="All 开发 框架 "
           href="/xiaomaer-sss/2023/01/26/Sentinel/"
           data-tag="Spring Cloud Alibaba"
           data-author="" >
            <span class="post-title" title="Sentinel">Sentinel</span>
            <span class="post-date" title="2023-01-26 21:39:44">2023/01/26</span>
        </a>
        
        
        <a  class="All 开发 框架 "
           href="/xiaomaer-sss/2023/01/26/Seata/"
           data-tag="Spring Cloud Alibaba"
           data-author="" >
            <span class="post-title" title="Seata">Seata</span>
            <span class="post-date" title="2023-01-26 21:39:44">2023/01/26</span>
        </a>
        
        
        <a  class="All 开发 框架 "
           href="/xiaomaer-sss/2023/01/26/Ribbon/"
           data-tag="Spring Cloud Alibaba"
           data-author="" >
            <span class="post-title" title="Ribbon">Ribbon</span>
            <span class="post-date" title="2023-01-26 21:39:44">2023/01/26</span>
        </a>
        
        
        <a  class="All 开发 疑难杂症 "
           href="/xiaomaer-sss/2023/01/26/github%E6%8B%89%E5%8F%96%E4%BB%A3%E7%A0%81%E6%8A%A5%20git@github.com's%20password/"
           data-tag="Bug"
           data-author="" >
            <span class="post-title" title="github拉取代码报 &#34;git@github.com&#39;s password&#34;">github拉取代码报 &#34;git@github.com&#39;s password&#34;</span>
            <span class="post-date" title="2023-01-26 21:39:44">2023/01/26</span>
        </a>
        
        
        <a  class="All 开发 疑难杂症 "
           href="/xiaomaer-sss/2023/01/26/gitee%E6%90%AD%E5%BB%BA%E4%B8%AA%E4%BA%BA%E5%8D%9A%E5%AE%A2%E6%95%99%E7%A8%8B/"
           data-tag="Bug"
           data-author="" >
            <span class="post-title" title="gitee搭建个人博客教程">gitee搭建个人博客教程</span>
            <span class="post-date" title="2023-01-26 21:39:44">2023/01/26</span>
        </a>
        
        
        <a  class="All 开发 框架 "
           href="/xiaomaer-sss/2023/01/26/GateWay/"
           data-tag="Spring Cloud Alibaba"
           data-author="" >
            <span class="post-title" title="GateWay">GateWay</span>
            <span class="post-date" title="2023-01-26 21:39:44">2023/01/26</span>
        </a>
        
        
        <a  class="All 开发 框架 "
           href="/xiaomaer-sss/2023/01/26/Fegin/"
           data-tag="Spring Cloud Alibaba"
           data-author="" >
            <span class="post-title" title="Fegin">Fegin</span>
            <span class="post-date" title="2023-01-26 21:39:44">2023/01/26</span>
        </a>
        
        
        <a  class="All 开发 框架 "
           href="/xiaomaer-sss/2023/01/20/Nacos/"
           data-tag="Spring Cloud Alibaba"
           data-author="" >
            <span class="post-title" title="Nacos">Nacos</span>
            <span class="post-date" title="2023-01-20 17:12:00">2023/01/20</span>
        </a>
        
        
        <a  class="All 开发 Java "
           href="/xiaomaer-sss/2023/01/17/hello-world/"
           data-tag="Java"
           data-author="" >
            <span class="post-title" title="Hello World">Hello World</span>
            <span class="post-date" title="2023-01-17 15:40:39">2023/01/17</span>
        </a>
        
        <div id="no-item-tips">

        </div>
    </nav>
    <div id="outline-list">
    </div>
</div>

    </div>
    <div class="hide-list">
        <div class="semicircle" data-title="切换全屏 快捷键 s">
            <div class="brackets first"><</div>
            <div class="brackets">&gt;</div>
        </div>
    </div>
</aside>
<div id="post">
    <div class="pjax">
        <article id="post-Java-基础（面试）" class="article article-type-post" itemscope itemprop="blogPost">
    
        <h1 class="article-title">Java-基础（面试）</h1>
    
    <div class="article-meta">
        
        
        
        <span class="book">
            <i class="iconfont icon-category"></i>
            
            
            <a  data-rel="开发">开发</a> > 
            
            <a  data-rel="开发&lt;---&gt;Java">Java</a>
            
        </span>
        
        
        <span class="tag">
            <i class="iconfont icon-tag"></i>
            
            <a class="color2">Java基础</a>
            
        </span>
        
    </div>
    <div class="article-meta">
        
            Created At : <time class="date" title='Updated At: 2023-02-02 21:13:16'>2023-01-27 19:42</time>
        
    </div>
    <div class="article-meta">
        
        <span>Count:2.7k</span>
        
        
        <span id="busuanzi_container_page_pv">
            Views 👀 :<span id="busuanzi_value_page_pv">
                <span class="count-comment">
                    <span class="spinner">
                      <div class="cube1"></div>
                      <div class="cube2"></div>
                    </span>
                </span>
            </span>
        </span>
        
        
    </div>
    
    <div class="toc-ref">
    
        <ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#Java%E4%B8%AD%E5%9F%BA%E6%9C%AC%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B%E6%9C%89%E5%93%AA%E4%BA%9B%EF%BC%8C%E5%AF%B9%E5%BA%94%E5%B0%81%E8%A3%85%E7%B1%BB%EF%BC%8C%E5%A4%A7%E5%B0%8F"><span class="toc-text">Java中基本数据类型有哪些，对应封装类，大小</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%92%8Cequals-%E7%9A%84%E5%8C%BA%E5%88%AB"><span class="toc-text">&#x3D;&#x3D;和equals()的区别</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Object%E4%B8%AD%E5%AE%9A%E4%B9%89%E4%BA%86%E9%82%A3%E4%BA%9B%E6%96%B9%E6%B3%95"><span class="toc-text">Object中定义了那些方法</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#String-StringBuilder-StringBuffer-%E7%9A%84%E5%8C%BA%E5%88%AB"><span class="toc-text">String, StringBuilder, StringBuffer 的区别</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Java%E4%B8%AD%E6%9C%89%E5%93%AA%E4%BA%9B%E5%BC%95%E7%94%A8"><span class="toc-text">Java中有哪些引用</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Java%E4%B8%AD%E5%88%9B%E5%BB%BA%E5%AF%B9%E8%B1%A1%E6%9C%89%E5%87%A0%E7%A7%8D%E6%96%B9%E5%BC%8F"><span class="toc-text">Java中创建对象有几种方式</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%B7%B1%E6%8B%B7%E8%B4%9D%E5%8F%AF%E6%B5%85%E6%8B%B7%E8%B4%9D%E7%9A%84%E5%8C%BA%E5%88%AB"><span class="toc-text">深拷贝可浅拷贝的区别</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%8A%BD%E8%B1%A1%E7%B1%BB%E5%92%8C%E6%8E%A5%E5%8F%A3%E7%9A%84%E5%8C%BA%E5%88%AB"><span class="toc-text">抽象类和接口的区别</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#switch%E6%94%AF%E6%8C%81%E7%9A%84%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B%E6%9C%89%E5%93%AA%E4%BA%9B"><span class="toc-text">switch支持的数据类型有哪些</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E9%87%8D%E8%BD%BD%E5%92%8C%E9%87%8D%E5%86%99%E7%9A%84%E5%8C%BA%E5%88%AB"><span class="toc-text">重载和重写的区别</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%B1%BB%E5%88%9D%E5%A7%8B%E5%8C%96%E7%9A%84%E9%A1%BA%E5%BA%8F"><span class="toc-text">类初始化的顺序</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E8%AE%BF%E9%97%AE%E6%8E%A7%E5%88%B6%E6%9D%83%E9%99%90%E7%9A%84%E4%BD%9C%E7%94%A8%E5%9F%9F"><span class="toc-text">访问控制权限的作用域</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E8%8E%B7%E5%8F%96ClassLoader%E7%9A%84%E6%96%B9%E5%BC%8F"><span class="toc-text">获取ClassLoader的方式</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E8%8E%B7%E5%8F%96Class%E5%AF%B9%E8%B1%A1%E7%9A%84%E6%96%B9%E5%BC%8F"><span class="toc-text">获取Class对象的方式</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%BC%80%E5%90%AF%E7%BA%BF%E7%A8%8B%E7%9A%84%E5%87%A0%E7%A7%8D%E6%96%B9%E5%BC%8F"><span class="toc-text">开启线程的几种方式</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%B8%B8%E7%94%A8%E7%9A%84%E7%BA%BF%E7%A8%8B%E6%B1%A0%E6%9C%89%E5%93%AA%E4%BA%9B"><span class="toc-text">常用的线程池有哪些</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%AE%80%E8%BF%B0%E4%B8%80%E4%B8%8B%E4%BD%A0%E5%AF%B9%E7%BA%BF%E7%A8%8B%E6%B1%A0%E7%9A%84%E7%90%86%E8%A7%A3"><span class="toc-text">简述一下你对线程池的理解</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%BA%BF%E7%A8%8B%E6%B1%A0%E4%B8%AD%E7%9A%84execute-%E5%92%8Csubmit-%E6%96%B9%E6%B3%95%E7%9A%84%E5%8C%BA%E5%88%AB"><span class="toc-text">线程池中的execute()和submit()方法的区别</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#CountDownLatch%E5%92%8CCyclicBarrier%E7%9A%84%E5%8C%BA%E5%88%AB"><span class="toc-text">CountDownLatch和CyclicBarrier的区别</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%BA%BF%E7%A8%8B%E7%9A%84%E7%94%9F%E5%91%BD%E5%91%A8%E6%9C%9F"><span class="toc-text">线程的生命周期</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#transient%E5%85%B3%E9%94%AE%E5%AD%97"><span class="toc-text">transient关键字</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#notify-%E5%92%8CnotifyAll-%E7%9A%84%E5%8C%BA%E5%88%AB"><span class="toc-text">notify()和notifyAll()的区别</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#sleep-%E5%92%8Cwait-%E7%9A%84%E5%8C%BA%E5%88%AB"><span class="toc-text">sleep()和wait()的区别</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#String%E7%9A%84equals%E6%96%B9%E6%B3%95%E6%98%AF%E5%A6%82%E4%BD%95%E6%AF%94%E8%BE%83%E7%9A%84"><span class="toc-text">String的equals方法是如何比较的</span></a></li></ol>
    
<style>
    .left-col .switch-btn,
    .left-col .switch-area {
        display: none;
    }
    .toc-level-3 i,
    .toc-level-3 ol {
        display: none !important;
    }
</style>
</div>
    
    <div class="article-entry" itemprop="articleBody">
      
        <h2 id="Java中基本数据类型有哪些，对应封装类，大小"><a href="#Java中基本数据类型有哪些，对应封装类，大小" class="headerlink" title="Java中基本数据类型有哪些，对应封装类，大小"></a>Java中基本数据类型有哪些，对应封装类，大小</h2><table>
<thead>
<tr>
<th align="center">基础类型</th>
<th align="center">封装类型</th>
<th align="center">大小(单位：Byte)</th>
<th align="center">默认值</th>
</tr>
</thead>
<tbody><tr>
<td align="center">byte</td>
<td align="center">Byte</td>
<td align="center">1</td>
<td align="center">0</td>
</tr>
<tr>
<td align="center">short</td>
<td align="center">Short</td>
<td align="center">2</td>
<td align="center">0</td>
</tr>
<tr>
<td align="center">int</td>
<td align="center">Integer</td>
<td align="center">4</td>
<td align="center">0</td>
</tr>
<tr>
<td align="center">long</td>
<td align="center">Long</td>
<td align="center">8</td>
<td align="center">0L</td>
</tr>
<tr>
<td align="center">float</td>
<td align="center">Float</td>
<td align="center">4</td>
<td align="center">0.0f</td>
</tr>
<tr>
<td align="center">double</td>
<td align="center">Double</td>
<td align="center">8</td>
<td align="center">0.0d</td>
</tr>
<tr>
<td align="center">boolean</td>
<td align="center">Boolean</td>
<td align="center">1</td>
<td align="center">false</td>
</tr>
<tr>
<td align="center">char</td>
<td align="center">Character</td>
<td align="center">2</td>
<td align="center">\u0000</td>
</tr>
</tbody></table>
<p>说明：null只能赋值给包装类型，不能赋值给基本数据类型</p>
<h2 id="和equals-的区别"><a href="#和equals-的区别" class="headerlink" title="==和equals()的区别"></a>==和equals()的区别</h2><p>==比较的是地址值，equals()比较的是值</p>
<p>equals()是Object类的方法，在Object中对equals()方法实现比较的也是地址值（使用了==来判断）。类库中的String，Date等类都对equals()方法进行了重写。</p>
<p>对于枚举类型和基本数据类型的相等性比较，应该使用==；对于引用类型的相等性比较，应该使用 equals() 方法。</p>
<h2 id="Object中定义了那些方法"><a href="#Object中定义了那些方法" class="headerlink" title="Object中定义了那些方法"></a>Object中定义了那些方法</h2><ol>
<li>getClass()</li>
<li>hashCode()</li>
<li>equals()</li>
<li>clone()</li>
<li>toString()</li>
<li>notify()</li>
<li>notifyAll()</li>
<li>wait()</li>
<li>finalize()</li>
</ol>
<h2 id="String-StringBuilder-StringBuffer-的区别"><a href="#String-StringBuilder-StringBuffer-的区别" class="headerlink" title="String, StringBuilder, StringBuffer 的区别"></a>String, StringBuilder, StringBuffer 的区别</h2><p>String: 不可变的字符序列，若要向其中添加新字符需要创建一个新的String 对象</p>
<p>StringBuilder: 可变字符序列，支持向其中添加新字符（无需创建新对象）</p>
<p>StringBuffer: 可以看作线程安全版的 StringBuilder</p>
<h2 id="Java中有哪些引用"><a href="#Java中有哪些引用" class="headerlink" title="Java中有哪些引用"></a>Java中有哪些引用</h2><ul>
<li>强引用<br>通常我们使用 new 关键字创建一个对象时所返回的引用即为强引用</li>
<li>软引用<br>若一个对象只能通过软引用到达，那么这个对象在内存不足时会被回收，可用于图片缓存中，内存不足时系统会自动回收不再使用的Bitmap</li>
<li>弱引用<br>若一个对象只能通过弱引用到达，那么它就会被回收（即使内存充足），同样可用于图片缓存中，这时候只要 Bitmap 不再使用就会被回收</li>
<li>虚引用<br>虚引用是 Java 中最“弱”的引用，通过它甚至无法获取被引用的对象，它存在的唯一作用就是当它指向的对象回收时，它本身会被加入到引用队列中，这样我们可以知道它指向的对象何时被销毁</li>
</ul>
<p>不同可达性状态的转换图如下：</p>
<p><img src="https://gitee.com/xiaomaer-sss/picgo/raw/master/images/2023/image-20230129111603054.png" alt="image-20230129111603054"></p>
<p>判断可达性条件，也是 JVM 垃圾收集器决定如何处理对象的一部分考虑因素。</p>
<h2 id="Java中创建对象有几种方式"><a href="#Java中创建对象有几种方式" class="headerlink" title="Java中创建对象有几种方式"></a>Java中创建对象有几种方式</h2><ul>
<li>new关键字创建</li>
<li>通过反射创建</li>
<li>采用clone机制</li>
<li>通过序列化机制</li>
</ul>
<h2 id="深拷贝可浅拷贝的区别"><a href="#深拷贝可浅拷贝的区别" class="headerlink" title="深拷贝可浅拷贝的区别"></a>深拷贝可浅拷贝的区别</h2><ul>
<li><p><strong>浅拷贝</strong><br>被复制对象的所有变量都含有与原来的对象相同的值，而所有的对其他对象的引用仍然指向原来的对象。换言之,浅拷贝仅仅复制所拷的对象，而不复制它所引用的对象。</p>
</li>
<li><p><strong>深拷贝</strong><br>被复制对象的所有变量都含有与原来的对象相同的值，而那些引用其他对象的变量将指向被复制过的新对象，而不再是原有的那些被引用的对象。换言之，深拷贝把要复制的对象所引用的对象都复制了一遍。</p>
</li>
</ul>
<h2 id="抽象类和接口的区别"><a href="#抽象类和接口的区别" class="headerlink" title="抽象类和接口的区别"></a>抽象类和接口的区别</h2><p>抽象类定义的是什么，接口定义的是能做什么</p>
<p>区别：</p>
<table>
<thead>
<tr>
<th align="center"></th>
<th align="center">抽象类</th>
<th align="center">接口</th>
</tr>
</thead>
<tbody><tr>
<td align="center">构造方法</td>
<td align="center">有，用于子类实例化使用</td>
<td align="center">无</td>
</tr>
<tr>
<td align="center">成员变量</td>
<td align="center">可以是变量，也可以是常量</td>
<td align="center">只能是常量，默认public static final修饰</td>
</tr>
<tr>
<td align="center">成员方法</td>
<td align="center">可以是抽象，也可以非抽象</td>
<td align="center">1.7只能是抽象的，默认public abstract修饰<br />1.8可以用default和static修饰</td>
</tr>
</tbody></table>
<h2 id="switch支持的数据类型有哪些"><a href="#switch支持的数据类型有哪些" class="headerlink" title="switch支持的数据类型有哪些"></a>switch支持的数据类型有哪些</h2><p>switch语句实际上只支持int类型，其他的类型实际上都是转换成了int类型。一共支持10中类型。</p>
<p>byte、char、short、int   以及他们的包装类型</p>
<p>String、Enum</p>
<h2 id="重载和重写的区别"><a href="#重载和重写的区别" class="headerlink" title="重载和重写的区别"></a>重载和重写的区别</h2><p><strong>重载</strong>：每个重载的方法都有独一无二的参数列表。其中包括参数的类型、顺序、参数数量等。满足其中一个条件就构成了重载的必要条件。</p>
<p>重载的条件</p>
<ul>
<li>方法名必须相同</li>
<li>参数列表必须不同（个数不同、类型不同、参数类型排列顺序不同等）</li>
<li>方法的返回值类型可以相同也可以不相同</li>
<li>仅仅返回值类型不同不构成方法的重载</li>
<li>重载是发生在编译时的，这样编译器就可以根据参数类型来选择使用哪一个重载的方法</li>
</ul>
<p><strong>重写</strong>：描述的是子类和父类之间，而重载是同一类中。</p>
<ul>
<li>重写的方法必须和父类保持一致，包括返回值类型，方法名和参数列表</li>
<li>重写的方法可以使用@Override注解来标识</li>
<li>子类中重写的方法的访问权限不能低于父类中方法的访问权限</li>
</ul>
<h2 id="类初始化的顺序"><a href="#类初始化的顺序" class="headerlink" title="类初始化的顺序"></a>类初始化的顺序</h2><ol>
<li>静态属性：static开头定义的属性</li>
<li>静态方法块：static{}包起来的代码块</li>
<li>普通属性：非static定义的属性</li>
<li>普通方法块：{}包起来的代码块</li>
<li>构造函数：类名相同的构造方法</li>
<li>方法：普通方法</li>
</ol>
<h2 id="访问控制权限的作用域"><a href="#访问控制权限的作用域" class="headerlink" title="访问控制权限的作用域"></a>访问控制权限的作用域</h2><p>Java中成员的访问权限有四种，分别是public、protected、default、private。可见性如下表：</p>
<table>
<thead>
<tr>
<th align="center"></th>
<th align="center">private</th>
<th align="center">default</th>
<th align="center">protected</th>
<th align="center">public</th>
</tr>
</thead>
<tbody><tr>
<td align="center">同一类</td>
<td align="center">√</td>
<td align="center">√</td>
<td align="center">√</td>
<td align="center">√</td>
</tr>
<tr>
<td align="center">同一包中的类</td>
<td align="center"></td>
<td align="center">√</td>
<td align="center">√</td>
<td align="center">√</td>
</tr>
<tr>
<td align="center">子类</td>
<td align="center"></td>
<td align="center"></td>
<td align="center">√</td>
<td align="center">√</td>
</tr>
<tr>
<td align="center">其他包中的类</td>
<td align="center"></td>
<td align="center"></td>
<td align="center"></td>
<td align="center">√</td>
</tr>
</tbody></table>
<h2 id="获取ClassLoader的方式"><a href="#获取ClassLoader的方式" class="headerlink" title="获取ClassLoader的方式"></a>获取ClassLoader的方式</h2><p>ClassLoader是用来把类（class）装载进JVM的，ClassLoader使用的是双亲委托模型来搜索加载类的，这个模型也是双亲委派模型。</p>
<p>ClassLoader的分类如下：</p>
<p>说明：四层之间的关系是包含与被包含的关系，不是上层与下层关系，也不是父类与子类的关系。</p>
<p><img src="https://gitee.com/xiaomaer-sss/picgo/raw/master/images/2023/image-20230129101242781.png" alt="image-20230129101242781"></p>
<p>ClassLoader获取方式如下：</p>
<pre><code class="java">// 方式一:获取当前类的classLoader
// clazz为Class对象
clazz.getclassLoader();

// 方式二:获取系统的classLoader
ClassLoader.getSystemClassLoader();

// 方式三:获取当前线程上下文的ClassLoader
Thread.currentThread () .getContextClassLoader();

// 方式四:获取调用者的classLoader
DriverManager.getCallerclassLoader();
</code></pre>
<h2 id="获取Class对象的方式"><a href="#获取Class对象的方式" class="headerlink" title="获取Class对象的方式"></a>获取Class对象的方式</h2><pre><code class="java">// 类名.class
Class&lt;String&gt; stringClass = String.class;
// 对象.getClass()
Class&lt;? extends String&gt; aClass = new String().getClass();
// Class.forName()
Class&lt;?&gt; aClass1 = Class.forName(&quot;java.lang.String&quot;);
// ClassLoader.loadClass()
Class&lt;?&gt; aClass2 = String.class.getClassLoader().loadClass(&quot;java.lang.String&quot;);
</code></pre>
<h2 id="开启线程的几种方式"><a href="#开启线程的几种方式" class="headerlink" title="开启线程的几种方式"></a>开启线程的几种方式</h2><ol>
<li>继承Thread类</li>
<li>实现Runnable接口</li>
<li>实现Callable接口</li>
<li>创建线程池</li>
</ol>
<h2 id="常用的线程池有哪些"><a href="#常用的线程池有哪些" class="headerlink" title="常用的线程池有哪些"></a>常用的线程池有哪些</h2><ul>
<li>newSingleThreadExecutor<br>创建一个单线程的线程池，此线程池保证所有任务的执行顺序按照任务的提交顺序执行</li>
<li>newFixedThreadPool<br>创建固定大小的线程池，每次提交一个任务就创建一个线程，直到线程达到线程池的最大大小</li>
<li>newCachedThreadPool<br>创建一个可缓存的线程池，此线程池不会对线程池大小做限制，线程池大小完全依赖于操作系统（或者说JVM）能够创建的最大线程大小</li>
<li>newScheduledThreadPool<br>创建定长的线程池，此线程池支持定时以及周期性执行任务的需求</li>
</ul>
<h2 id="简述一下你对线程池的理解"><a href="#简述一下你对线程池的理解" class="headerlink" title="简述一下你对线程池的理解"></a>简述一下你对线程池的理解</h2><ul>
<li>降低资源消耗。通过重复利用已创建的线程降低线程创建和销毁造成的消耗</li>
<li>提高响应速度。当任务到达时，任务可以不需要等到线程创建就能立即执行</li>
<li>提高线程的可管理性。线程是稀缺资源，如果无限制的创建，不仅会消耗系统资源，还会降低系统的稳定性，使用线程池可以进行统一的分配，调优和监控</li>
</ul>
<h2 id="线程池中的execute-和submit-方法的区别"><a href="#线程池中的execute-和submit-方法的区别" class="headerlink" title="线程池中的execute()和submit()方法的区别"></a>线程池中的execute()和submit()方法的区别</h2><p>execute()和submit()都是属于线程池的方法。</p>
<table>
<thead>
<tr>
<th align="center"></th>
<th align="center">execute()</th>
<th align="center">submit()</th>
</tr>
</thead>
<tbody><tr>
<td align="center">提交任务的类型</td>
<td align="center">Runnable类型、Callable类型</td>
<td align="center">Runnable类型</td>
</tr>
<tr>
<td align="center">异常</td>
<td align="center">会抛出异常，可以使用try/catch捕获</td>
<td align="center">会吃掉异常，可通过Future的get方法获取异常</td>
</tr>
<tr>
<td align="center">返回值</td>
<td align="center">无返回值</td>
<td align="center">有返回值</td>
</tr>
</tbody></table>
<p>如果提交的任务不需要一个结果的话直接使用execute()方法会提高性能。</p>
<h2 id="CountDownLatch和CyclicBarrier的区别"><a href="#CountDownLatch和CyclicBarrier的区别" class="headerlink" title="CountDownLatch和CyclicBarrier的区别"></a>CountDownLatch和CyclicBarrier的区别</h2><p>CountDownLatch：一个倒数的计数器阀门，初始化时阀门关闭，指定计数的数量，当数量倒数减到0时阀门打开，被阻塞线程被唤醒。</p>
<p>CyclicBarrier：一个可循环的屏障，它允许多个线程在执行完相应的操作后彼此等待共同到达一个point，等所有线程都到达后再继续执行。</p>
<p>两者都适用于多个子任务并发执行，当所有子任务都执行完后再继续接下来的工作。</p>
<p>两者区别如下：</p>
<table>
<thead>
<tr>
<th align="center"></th>
<th align="center">CountDownLatch</th>
<th align="center">CyclicBarrier</th>
</tr>
</thead>
<tbody><tr>
<td align="center">await()方法</td>
<td align="center">线程会等待计数器减为0</td>
<td align="center">会使线程进入阻塞等待其他线程到达障点</td>
</tr>
<tr>
<td align="center">能否重置</td>
<td align="center">不能</td>
<td align="center">可以</td>
</tr>
<tr>
<td align="center">实现方式</td>
<td align="center">基于AQS的共享模式实现</td>
<td align="center">基于ReentrantLock和Condition实现</td>
</tr>
<tr>
<td align="center">子线程是否阻塞</td>
<td align="center">不会</td>
<td align="center">会使所有子线程进入阻塞</td>
</tr>
</tbody></table>
<h2 id="线程的生命周期"><a href="#线程的生命周期" class="headerlink" title="线程的生命周期"></a>线程的生命周期</h2><p>新建，就绪，运行，阻塞，死亡</p>
<h2 id="transient关键字"><a href="#transient关键字" class="headerlink" title="transient关键字"></a>transient关键字</h2><p>对于不想进行序列化的变量，使用transient关键字修饰。</p>
<p>transient关键字的作用是：阻止实例中那些用此关键字修饰的的变量序列化。当对象被反序列化时，被 transient 修饰的变量值不会被持久化和恢复。transient只能修饰变量，不能修饰类和方法。</p>
<h2 id="notify-和notifyAll-的区别"><a href="#notify-和notifyAll-的区别" class="headerlink" title="notify()和notifyAll()的区别"></a>notify()和notifyAll()的区别</h2><p>两者都是用来唤醒调用wait()方法进入等待锁资源队列的线程。二者的区别在于：</p>
<ul>
<li><p>notify可能会导致死锁，而notifyAll则不会</p>
</li>
<li><p>使用notifyall可以唤醒所有处于wait状态的线程，使其重新进入锁的争夺队列中，而notify只能唤醒一个</p>
</li>
</ul>
<h2 id="sleep-和wait-的区别"><a href="#sleep-和wait-的区别" class="headerlink" title="sleep()和wait()的区别"></a>sleep()和wait()的区别</h2><p>对于sleep()方法，我们首先要知道该方法是属于Thread类中的。而wait()方法，则是属于Object类中 的。 </p>
<p>sleep()方法导致了程序暂停执行指定的时间，让出cpu给其他线程，但是他的监控状态依然保持者，当指定的时间到了又会自动恢复运行状态。在调用sleep()方法的过程中，线程不会释放对象锁。 当调用wait()方法的时候，线程会放弃对象锁，进入等待此对象的等待锁定池，只有针对此对象调用notify()方法后本线程才进入对象锁定池准备，获取对象锁进入运行状态。</p>
<h2 id="String的equals方法是如何比较的"><a href="#String的equals方法是如何比较的" class="headerlink" title="String的equals方法是如何比较的"></a>String的equals方法是如何比较的</h2><p>先用==判断地址是否一样，字符串有个常量池，如果一样就返回true。然后判断长度，再然后循环比较字符串的每一个字符是否一样</p>

      
       <hr><span style="font-style: italic;color: gray;"> 转载请注明来源，欢迎对文章中的引用来源进行考证，欢迎指出任何有错误或不够清晰的表达。可以邮件至 jackma.h@foxmail.com </span>
    </div>
</article>


<p>
    <a  class="dashang" onclick="dashangToggle()">💰</a>
</p>






    




    </div>
    <div class="copyright">
        <p class="footer-entry">
    ©2017 kiwi
</p>
<p class="footer-entry">Built with <a href="https://hexo.io/" target="_blank">Hexo</a> and <a href="https://github.com/yelog/hexo-theme-3-hexo" target="_blank">3-hexo</a> theme</p>

    </div>
    <div class="full-toc">
        <button class="full" data-title="切换全屏 快捷键 s"><span class="min "></span></button>
<a class="" id="rocket" ></a>

    </div>
</div>

<div class="hide_box" onclick="dashangToggle()"></div>
<div class="shang_box">
    <a class="shang_close"  onclick="dashangToggle()">×</a>
    <div class="shang_tit">
        <p>Help us with donation</p>
    </div>
    <div class="shang_payimg">
        <div class="pay_img">
            <img src="/img/alipay.jpg" class="alipay" title="扫码支持">
            <img src="/img/weixin.jpg" class="weixin" title="扫码支持">
        </div>
    </div>
    <div class="shang_payselect">
        <span><label><input type="radio" name="pay" checked value="alipay">alipay</label></span><span><label><input type="radio" name="pay" value="weixin">weixin</label></span>
    </div>
</div>


</body>
<script src="/js/jquery.pjax.js?v=1.1.0" ></script>

<script src="/js/script.js?v=1.1.0" ></script>
<script>
    var img_resize = 'default';
    function initArticle() {
        /*渲染对应的表格样式*/
        
            $("#post .pjax table").addClass("green_title");
        

        /*渲染打赏样式*/
        
        $("input[name=pay]").on("click", function () {
            if($("input[name=pay]:checked").val()=="weixin"){
                $(".shang_box .shang_payimg .pay_img").addClass("weixin_img");
            } else {
                $(".shang_box .shang_payimg .pay_img").removeClass("weixin_img");
            }
        })
        

        /*高亮代码块行号*/
        

        /*访问数量*/
        
        $.getScript("//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js");
        

        /*代码高亮，行号对齐*/
        $('.pre-numbering').css('line-height',$('.has-numbering').css('line-height'));

        
        
    }

    /*打赏页面隐藏与展示*/
    
    function dashangToggle() {
        $(".shang_box").fadeToggle();
        $(".hide_box").fadeToggle();
    }
    

</script>

<!--加入行号的高亮代码块样式-->

<!--自定义样式设置-->
<style>
    
    
    .nav {
        width: 542px;
    }
    .nav.fullscreen {
        margin-left: -542px;
    }
    .nav-left {
        width: 120px;
    }
    
    
    @media screen and (max-width: 1468px) {
        .nav {
            width: 492px;
        }
        .nav.fullscreen {
            margin-left: -492px;
        }
        .nav-left {
            width: 100px;
        }
    }
    
    
    @media screen and (max-width: 1024px) {
        .nav {
            width: 492px;
            margin-left: -492px
        }
        .nav.fullscreen {
            margin-left: 0;
        }
    }
    
    @media screen and (max-width: 426px) {
        .nav {
            width: 100%;
        }
        .nav-left {
            width: 100%;
        }
    }
    
    
    .nav-right .title-list nav a .post-title, .nav-right .title-list #local-search-result a .post-title {
        color: #383636;
    }
    
    
    .nav-right .title-list nav a .post-date, .nav-right .title-list #local-search-result a .post-date {
        color: #5e5e5f;
    }
    
    
    .nav-right nav a.hover, #local-search-result a.hover{
        background-color: #e2e0e0;
    }
    
    

    /*列表样式*/
    
    #post .pjax article .article-entry>ol, #post .pjax article .article-entry>ul, #post .pjax article>ol, #post .pjax article>ul{
        border: #e2dede solid 1px;
        border-radius: 10px;
        padding: 10px 32px 10px 56px;
    }
    #post .pjax article .article-entry li>ol, #post .pjax article .article-entry li>ul,#post .pjax article li>ol, #post .pjax article li>ul{
        padding-top: 5px;
        padding-bottom: 5px;
    }
    #post .pjax article .article-entry>ol>li, #post .pjax article .article-entry>ul>li,#post .pjax article>ol>li, #post .pjax article>ul>li{
        margin-bottom: auto;
        margin-left: auto;
    }
    #post .pjax article .article-entry li>ol>li, #post .pjax article .article-entry li>ul>li,#post .pjax article li>ol>li, #post .pjax article li>ul>li{
        margin-bottom: auto;
        margin-left: auto;
    }
    

    /* 背景图样式 */
    
    #post {
        background: url([object Object]);
    }
    
    
    #post .index {
        background: url([object Object]);
    }
    


    /*引用块样式*/
    

    /*文章列表背景图*/
    
    .nav-right:before {
        content: ' ';
        display: block;
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
        height: 100%;
        opacity: 0.3;
        background: url("https://i.loli.net/2019/07/22/5d3521411f3f169375.png");
        background-repeat: no-repeat;
        background-position: 50% 0;
        -ms-background-size: cover;
        -o-background-size: cover;
        -moz-background-size: cover;
        -webkit-background-size: cover;
        background-size: cover;
    }
    

    
</style>







</html>
